CXX=g++
LDFLAGS= -lpthread -lprotobuf -lrt -lz -lstdc++fs 
CXXFLAGS= -Wall -w -g -ggdb -O0 -std=c++17 -Wno-unused -Wno-sign-compare -Wno-deprecated-declarations -Wno-deprecated -Wl,--no-as-needed -std=c++17 

.PHONY: clean all

all: echo_client echo_server

ifndef LIBNET_PATH
  $(warning Warning: missing libgrpc path, using default)
	LIBNET_PATH=../../../lib
endif
LIBNET_INCLUDE_DIR=$(LIBNET_PATH)
LIBNET_LIBRARY=$(LIBNET_PATH)/libgrpc.a

CXXFLAGS+= -I $(LIBNET_INCLUDE_DIR) -I ../../

DEP_LIBS = $(LIBNET_LIBRARY)
LDFLAGS := $(DEP_LIBS) $(LDFLAGS)

echo.pb.cc: echo.proto
	protoc -I=. --cpp_out=. ./$^

echo_client: echo_client.cc echo.pb.cc
	$(CXX) $(CXXFLAGS) $^ -o $@ $(LDFLAGS)

echo_server: echo_server.cc echo.pb.cc
	$(CXX) $(CXXFLAGS) $^ -o $@ $(LDFLAGS)

clean:
	find . -name "*.[oda]" -exec rm -f {} \;
	rm -rf echo_server echo_client
